package com.to8to.scene.datatransfer;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.to8to.commons.mongo.MongoClientBase;
import com.to8to.scene.data.DataFixIface;
import com.to8to.scene.server.Commons;
import com.to8to.scene.server.Tables;

/**
 * FixStaticConfigCateTypes.java
 * 作 者:alpha.ren
 * 版 本:v2.0
 * 日期:2015年1月12日
 * 描 述:修正日记数据中新清单分类问题
 */
public class FixStaticConfigCateType1 implements DataFixIface
{
    public static Logger logger = LoggerFactory.getLogger(FixStaticConfigTags.class);

    static Connection conn;

    public void fix(Connection mysql, MongoClientBase mongo) throws SQLException
    {
        DBCursor static_conf_cur =
            mongo.cursor(Tables.StaticConfigValue, new BasicDBObject("type_name", "category_type_1"), null, new BasicDBObject("parent_type_id", 1), 0, 0);
        if (static_conf_cur.hasNext())
        {
            DBObject static_conf_db = static_conf_cur.next();
            if (null != static_conf_db && null != static_conf_db.get("id_map"))
            {
                Map<String, String> temp_map = (Map<String, String>) static_conf_db.get("id_map");
                temp_map.put("6", "设计费");
                temp_map.put("7", "装修费");

                mongo.updateField(Tables.StaticConfigValue, new BasicDBObject("_id", static_conf_db.get("_id")), new BasicDBObject("id_map", temp_map));
                logger.debug("update {} for {}", static_conf_db.get("_id").toString(), temp_map);
            }
        }
    }

    public static void main(String[] args) throws SQLException, ConfigurationException
    {
        PropertiesConfiguration pc = new PropertiesConfiguration("common.properties");

        Commons.init(null);

        (new FixStaticConfigTags()).fix(conn, Commons.mongo);

        conn.close();
    }
}
